(function(app){
	app
		.controller("content_47_inputCtrl",["$scope","$state","myFactory",'$stateParams',"$q",'$timeout','$location','$http','$ionicHistory',function($scope,$state,myFactory,$stateParams,$q,$timeout,$location,$http,$ionicHistory){
			//参数定义、接收
			var itemId = $stateParams.changeTypeId;//变更项目ID
			var chdrnum01 =  $stateParams.chdrnum01; //保单号
			var chdrcoy = $stateParams.chdrcoy; //保单公司号码
			var policyData;//保单详情
			var policy;//保单数据
			var itemData;//用于接收初始化查询initContentItem的内容，里面存在各种各样的内容，比如item02_1
			var searchParam = $stateParams.searchParam;
			var initFlag = false;//检测标志，在初始化函数完成后，会被置为true
			var token=sessionStorage.getItem("token");
			
			//绑定参数到页面
			$scope.chdrnum01 = chdrnum01;
			$scope.declarationFlag = false;//声明标志，默认为false
			$scope.readFlag = false;//阅读协议标志，默认为false
			$scope.show47InputBorrowFlag = false;//默认不显示

			$scope.data = {
				checkFlag: false,
			};
			$scope.item47 = {
				"beneList" : []
			}

			/**********************************************初始化函数begin****************************************************/
			//初始化查询变更项内容
			$scope.load = function () {
				myFactory.loadingShow();//显示加载圈
				var timestamp=myFactory.getTimetamp();
				var sfis= "itemId-token-timestamp";
				var signStr="itemId="+itemId+"&token="+token+"&timestamp="+timestamp;//encodeURI(name)
				var sign = myFactory.hex(signStr);
				$http({
					method: 'GET',
					url: app.domain + 'input/initContentItem.action',
					params: {'itemId': itemId,'sign':sign,'sfis':sfis,'token':token,'timestamp':timestamp}
				}).then(function successCallback(response) {
					if (response.data.success) {
						itemData = response.data.data.modelMap;
						policy = response.data.data.policy;
						$scope.item47 = itemData.item47;
						var borrowMoney=$scope.item47.borrowMoney;
						if(parseFloat(borrowMoney) > 0){
							$scope.show47InputBorrowFlag = true;
						}
						initFlag=true;//标识初始化成功
					}
					myFactory.loadingHide();
				}, function errorCallback(response) {
					myFactory.loadingHide();
					myFactory.alert("","初始化查询变更项内容失败!","info");
				});
			}
			/**********************************************初始化函数end****************************************************/

			//重新受理
			$scope.renew = function(){
				myFactory.renew();
			}
			//退出移动保全
			$scope.exit = function(){
				myFactory.exit();
			}
			//返回上一页
			$scope.goBack = function(){
				myFactory.goBack();
			}
			//关闭遮罩
			$scope.overwindowClose = function(){
				$(".overwindow").hide();
				$(".overmodal").hide();
			}
			//保单详情弹框
			$scope.showPolicyDetail = function(){
				modal('open','policyModalOn47Input','overwindowOn47Input','policyCloseXOn47Input');
				var timestamp=myFactory.getTimetamp();
				var sfis= "chdrnum-chdrcoy-token-timestamp";
				var signStr="chdrnum="+chdrnum01+"&chdrcoy="+chdrcoy+"&token="+token+"&timestamp="+timestamp;//encodeURI(name)
				var sign = myFactory.hex(signStr);
				//初始化时候查询保单详情
				$http({
					method: 'GET',
					url: app.domain + 'query/restFindPolicyDetail.action',
					params: {'chdrnum': chdrnum01,'chdrcoy': chdrcoy,'sign':sign,'sfis':sfis,'token':token,'timestamp':timestamp}
				}).then(function successCallback(response) {
					if (response.data.success) {
						policyData = response.data.data;
						$scope.policyData = policyData;
						$scope.policyData.ptdate01=myFactory.DateTools($scope.policyData.ptdate01);
					}
				}, function errorCallback(response) {
					myFactory.alert("","初始化查询订单详情失败!","info");
				});
			}
			//保单详情弹窗关闭函数
			$scope.policyCancelOn47Input = function(){
				modal('close','policyModalOn47Input','overwindowOn47Input','policyCloseXOn47Input');
			}
			//S2019051508554《反洗钱监管-官微、移动保全增加核实投被保险关系功能需求》 add by csf 20190527 start
			//改变投保人和被保人关系的下拉框
			$scope.changePeoRelation = function(){
				var options = $('#peopleRelationCause option:selected');
				$('#peopleRelationInput').val(options.text());
			} 
			//S2019051508554《反洗钱监管-官微、移动保全增加核实投被保险关系功能需求》 add by csf 20190527 end
			//客户须知
			$scope.tipOpen = function(){
				modal('open','tip_model','overwindowOn47Input');
			}
			$scope.closeTip = function(){
				modal('close','tip_model','overwindowOn47Input');
			}
			//详情
			$scope.benifidDetail = function(index){
				console.log("index:"+index);
				$("#get_survival_dialog1").fadeToggle(50);

				var benifidContent = $scope.item47.beneList[index];

				$scope.clientNameContent=benifidContent.clientName;
				//$scope.clientNoContent=benifidContent.clientNo;
				$scope.clientNoContent=benifidContent.idCard;//获取的是客户证件号码，不是客户号，客户号属于敏感数据

				$("#get_survival_dialog1 .myDialog_content .btn_close").click(function(){
					$(this).parents('#get_survival_dialog1').fadeOut(50);
				});
				
				$("#get_survival_dialog1 .myDialog_black").click(function(){
					$(this).parent('#get_survival_dialog1').fadeOut(50);
				});

			}

			//页面同意阅读协议复选框部分
			$scope.changeReadFlag = function(){
				$scope.readFlag = !$scope.readFlag;
				console.log($scope.readFlag);
			}

			//下一步
			$scope.nextStep = function(){
				if(!initFlag){
					myFactory.alert("","初始化时失败，请返回上一步重试","info");
					return;
				}
				//S2019051508554《反洗钱监管-官微、移动保全增加核实投被保险关系功能需求》 add by csf 20190527 start
				var resonPeoRelationInput = $('#peopleRelationInput');
				if ( resonPeoRelationInput.val() == '' ||resonPeoRelationInput.val() == undefined ){ 
					myFactory.alert("","请选择投被保人关系","info");
					return;
				}
				var peopleRelationCause = $('#peopleRelationCause');
				if (peopleRelationCause.val() == '6' ){
					myFactory.alert("","投保人与被保险人非直系亲属关系，需由被保险人的监护人提出一同申请，请通过书面办理。","info");
					return;
				}
				//S2019051508554《反洗钱监管-官微、移动保全增加核实投被保险关系功能需求》 add by csf 20190527 end
				var readFlag = $scope.readFlag;
				if(readFlag==false){
					myFactory.alert("","请同意并阅读《申请须知》","info");
					return;
				}

				var actValue = $("#actValue").val();	//	本次领取生存金金额
				if(actValue=="" || actValue==undefined || actValue=="null"){
					myFactory.alert("","请输入领取金额!","info");
					return false;
				}

				if(parseFloat(actValue)== 0){
					myFactory.alert("","填写的本次领取生存金金额为0，请确认!","info");
					return false;
				}else{
					var reg = /^\d{0,8}\.{0,1}(\d{1,2})?$/;
					if(!reg.test(actValue)){
						myFactory.alert("","请填写正确生存金金额!","info");
						return false;
					}
				}
				actValue = parseFloat(actValue);
				//var amountMoney = parseFloat($("#amountMoney").val());
				var liveMoney = parseFloat($("#liveMoney").val());
				if(actValue>liveMoney){
					//myFactory.alert("","本次领取生存金金额大于合计可提取金额，需重新输入!","info");
					myFactory.alert("","本次领取生存金金额大于可领取生存金本息，需重新输入！","info");
					return false;
				}

				var item={
					"itemId":itemId,
					//S2019051508554《反洗钱监管-官微、移动保全增加核实投被保险关系功能需求》 add by csf 20190527 end
					"actValue":actValue,
					"peoRelation":peopleRelationCause.val()
					//S2019051508554《反洗钱监管-官微、移动保全增加核实投被保险关系功能需求》 add by csf 20190527 end
				}
				
				//CRS需求，增加个人税收页面  add by dll 2018-01-26 start
				//非一年期险种受理"领取生存金"时
				//当受益人(指生存金/年金/祝寿金/满期金受益人)非投保人，且国籍为非中国籍时，系统需自动带出填写受益人（不可修改）个人税收居民身份声明
				//备注：在移动保全系统中，受益人相当于被保人，所以直接带出被保人的个人税收居民身份证明资料
				if(!itemData.isOneYearCrtFlag){
					if(policy.base != null){
						//条件：一年期保单，受益人非投保人，国籍非中国
						var taxBenefitRole=itemData.taxBenefitRole;//受益人角色
						var taxClientNo=itemData.taxClientNo;//投保人/受益人客户号
						//CRS个人税收居民身份保全需求 增加控制填写投保人、受益人单次填写问题 add by rqyang 2018-12-08 begin
						//var benfitCrsIsexistsFlag=sessionStorage.getItem("BENFIT_CRS_ISEXISTS_FLAG");
						var benfitCrsIsexistsFlag="";
						var cownnum01=policy.base.cownnum01;
						var lifcnum01=policy.base.lifcnum01;
						if(cownnum01==lifcnum01){//投被保险人同一人
							benfitCrsIsexistsFlag=sessionStorage.getItem("HOLDER_CRS_ISEXISTS_FLAG");
						}else{
							benfitCrsIsexistsFlag=sessionStorage.getItem("BENFIT_CRS_ISEXISTS_FLAG");
						}
						var nationality="";
						var taxName="";
						if("bf"==taxBenefitRole){
							nationality=policy.base.rnNationality;
							taxName=policy.base.rnName;
						}else{
							nationality=policy.base.natlty;
							taxName=policy.base.surname;
						}
						if(nationality!="CHN" && benfitCrsIsexistsFlag=="N"){//受益人为非投保人，国籍为非中国国籍
							//CRS个人税收居民身份保全需求 增加控制填写投保人、受益人单次填写问题 add by rqyang 2018-12-08 end
							//if(policy.base.lifcnum01!=policy.base.cownnum01 && (policy.base.rnNationality!="CHN")){
							//&& policy.base.rnNationality!="HKG" && policy.base.rnNationality!="TWN" &&  policy.base.rnNationality!="MAC"
							$state.go('tax_info',{
								itemId:itemId,
								item:item,
								chdrnum:chdrnum01,
								chdrcoy:chdrcoy,
								taxBenefitRole:taxBenefitRole,
								taxClientNo:taxClientNo,
								taxName:taxName
							});
						}else{
							$ionicHistory.clearCache().then(function(){
								$state.go('content_check_main',{
									itemId:itemId,
									item:item,
									chdrnum01:chdrnum01,
									chdrcoy:chdrcoy,
									searchParam:searchParam
								});
							})
						}
					}
				}else{
					$ionicHistory.clearCache().then(function(){
						$state.go('content_check_main',{
							itemId:itemId,
							item:item,
							chdrnum01:chdrnum01,
							chdrcoy:chdrcoy,
							searchParam:searchParam
						});
					})
				}
				//CRS需求，增加个人税收页面  add by dll 2018-01-26 end

			
			}

		}]);

		//指针弹窗
		app.directive('infoid',function(){
			return {
				restrict: 'EA',		//指明指令在DOM里面以什么形式被声明,EA.表示即可以是元素也可以是属性
				templateUrl: 'html/input/content_base_info.html'+app.clearCache,
				replace: true,		//设置解析后，DOM声明的指令是否消失
				link: function(scope,element,attrs){  //链接函数负责注册DOM事件和更新DOM,
					console.log('指令完成');
				}
			}
		});

})(app)